﻿/*--------------------------------------------------------------
 * Author : Shine K Velayudhan 
 ---------------------------------------------------------------*/
namespace IQN.Logging
{
    public sealed class PerformanceMessage : LogMessage
    {
        public string Component { get; set; }
        public long DurationInTicks { get; set; }
        public string EventTag { get; set; }
        public string Tag1 { get; set; }
        public string Tag2 { get; set; }
        public PerformanceMessage(string messageSource, MessageLevel messageLevel, string eventTag, string component, long durationInTicks, string tag1, string tag2)
            : base(messageSource, messageLevel)
        {
            this.EventTag = base.ClipAndClean(eventTag, 32);
            this.Component = base.ClipAndClean(component, 64);
            this.DurationInTicks = durationInTicks;
            this.Tag1 = base.ClipAndClean(tag1, 32);
            this.Tag2 = base.ClipAndClean(tag2, 32);
        }
        public string Duration
        {
            get
            {
                float num = DurationInMilliSec;
                if (num < 1000f)
                {
                    return num.ToString("0.0 mSec");
                }
                num = num / 1000f;
                if (num < 60f)
                {
                    return num.ToString("0.0 sec");
                }
                num = num / 60f;
                return num.ToString("0.0 min");
            }
        }
        public long DurationInMilliSec
        {
            get
            {
                return (this.DurationInTicks / 10000L);
            }
        }
        public override string MessageText
        {
            get
            {
                return string.Format("{0}:{1} - {2}", this.EventTag, this.Component, this.Duration);
            }
        }
        public override MessageType MessageType
        {
            get
            {
                return MessageType.Performance;
            }
        }
    }
}
